const {ccclass, property} = cc._decorator;
import PrefabManager from '../xf/manager/PrefabManager';
import ViewBase from '../xf/ViewBase';
import MdGame from './MdGame';
import Plat from './../xf/Palt';
import MdSet from './MdSet';
import AndroidTool from './AndroidTool';
import SoundManager from '../manager/SoundManager';


@ccclass
export default class MdHome extends ViewBase {

    private static _inst:MdHome;

    public static get inst()
    {
        if(this._inst==null)
        {
            let v=cc.instantiate(PrefabManager.getPrefab("HomeView"));

            this._inst=v.getComponent(MdHome);
        }

        return this._inst;
    }

    public showView(data?: any): void {
        SoundManager.playBgm()
        if(cc.sys.platform==cc.sys.ANDROID){
            AndroidTool.Instance.onGoHome() 
        }
        super.showView(data)
    }

    protected onLoad(): void {
        var self=this
        let helper = {
            okGame : function(){
                self.realStartGame()
            }
        }
        window["home"]=helper; 
    }

    public realStartGame(){
        this.hideView();
        MdGame.inst.startGame();
    }

    public startGame()
    {
        if(cc.sys.platform==cc.sys.ANDROID){
            AndroidTool.Instance.onStartGame()
        }else{
            this.realStartGame()
        }
        
    }
    

    public onShare()
    {
       Plat.shareAppMessage();
    }

    public onRank()
    {
         
    }

    public onSet()
    {
        MdSet.inst.showView();
    }

    public onJump(event,appid)
    {
         if(Plat.pt.navigateToMiniProgram!=null)
         {
            Plat.pt.navigateToMiniProgram({
                "appId":appid
            });
         }
    }

    

}